|
|
|
|
|
|
|
Another group of common errors is caused by problems with physical media. Unresponsive printers, disk drives that do not contain diskettes, and downed communications ports are the most common examples of physical media errors. These errors might, or might not, be easily fixed by your user. Usually, you can report the error, wait for the user to fix the problem, and then continue with the process. For example, if the printer is jammed with paper, all you need to do is report the error to the user, and then wait for the OK to continue. |
|
|
|
|
|
|
|
|
Let's add another button to the PRJERRTYPES.VBP project to display an example of physical media error handling. Add a new command button to the project. Set its Caption property to &Media and its Name property to cmdMedia. Enter the code in Listing 14.10 into the cmdMedia_Click event. |
|
|
|
|
|
|
|
|
Listing 14.10. Trapping media errors. |
|
|
|
|
|
|
|
|
Private Sub cmdMedia_Click()
'
' show handling of media errors
'
On Error GoTo LocalErr
Dim strMsg As String
Dim lngReturn As Long
'
' open a file on the a drive
' an error will occur if there
' is no diskette in the drive
'
Open "a:\junk.txt" For Input As 1
Close #1
GoTo LocalExit
'
LocalErr:
If Err.Number = 71 Then
strMsg = "The disk drive is not ready." & vbCrLf
strMsg = strMsg + "Please make sure there is a diskette" & vbCrLf
strMsg = strMsg + "in the drive and the drive door is closed."
'
lngReturn = MsgBox(strMsg, vbCritical + vbRetryCancel, "cmdMedia")
'
If lngReturn = vbRetry Then
Resume
Else
Resume Next
End If
Else
MsgBox Str(Err.Number) & " - " & Err.Description
Resume Next |
|
|
|
|
|